package com.feihong.txgw.tx_precenter;

import com.feihong.txgw.inter.contract.llcx.ITelSpaceContract;
import com.feihong.txgw.model.bean.llcx.PhoneCardLocation;
import com.feihong.txgw.tx_model.TelSpaceMainModel;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName TelSpaceMainPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/7 17:24
 * @Describe
 * @Change
 */
public class TelSpaceMainPrecenter extends ITelSpaceContract.AbTelSpaceMainprecenter {

    public static TelSpaceMainPrecenter create(){
        return new TelSpaceMainPrecenter();
    }


    @Override
    public ITelSpaceContract.ITelSpaceMainModel getModel() {
        return TelSpaceMainModel.create();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void vertifyTelType(String telNum) {
        mIModel.vertifyTel(telNum).subscribe(new Observer<PhoneCardLocation>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(PhoneCardLocation phoneCardLocation) {
                mIView.vertifyTelResult(phoneCardLocation);
            }

            @Override
            public void onError(Throwable e) {
                mIView.vertifyTelError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void sendVertiryCode(String icpID, String telNum) {
        mIModel.sendVerityCode(icpID, telNum).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(String s) {
                mIView.sendVertifyCode(s);
            }

            @Override
            public void onError(Throwable e) {
                mIView.sendVertifyCodeError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void getTelSpace(String icpID, String telNum, String code) {
        mIModel.getTelSpace(icpID, telNum, code).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(String s) {
                mIView.getTelSpace(s);
            }

            @Override
            public void onError(Throwable e) {
                mIView.getTelSpaceError();
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
